【ABAP系列】SAP BOM反查

公众号:matinal
本文作者:matinal
 

 

前言部分

大家可以关注我的公众号,公众号里的排版更好,阅读更舒适。

正文部分

TCODE::CS15

或者函数::CS_WHERE_USED_MAT 

​

tables : stpo,stas,mara,makt.

data : begin of itab occurs 200,
       matnr like mast-matnr,
       menge like stpo-menge,
       end of itab.

data : begin of alttab occurs 200,
       matnr like mast-matnr,
       menge like stpo-menge,
       end of alttab.

data : begin of top_code occurs 100,
       matnr(18),
       maktx(40),
       meins(3),
       menge like stpo-menge,
       matkl(9),
       wrkst(14),
       end of top_code.

data : begin of makr occurs 10,
       maker(7),
       idnlf(22),
       end of makr.

data : begin of usedtab occurs 100.
        include structure stpov.
data : end of usedtab.

data : begin of equicat occurs 100.
        include structure  cscequi.
data : end of equicat.

data : begin of kndcat occurs 100.
        include structure  cscknd.
data : end of kndcat.

data : begin of matcat occurs 100.
        include structure  cscmat.
data : end of matcat.

data : begin of stdcat occurs 100.
        include structure   cscstd.
data : end of stdcat.

data : begin of tplcat occurs 100.
        include structure   csctpl.
data : end of tplcat.

data : top_cnt(5) type n,
       m_cnt(5) type n,
       lin(5) type n,
       line_cnt(5) type n.

selection-screen begin of block blk1 with frame.
selection-screen : comment 1(60) text-001,
                   skip.
parameters : matnr like marc-matnr obligatory,
             werks like marc-werks obligatory default 'PQ50'.
select-options : bdate for sy-datum default sy-datum to sy-datum
                 no-extension obligatory.
selection-screen end of block blk1.

start-of-selection.
  itab-matnr = matnr.
  itab-menge = 1.
  append itab.
  clear itab.

  perform get_top_code.

************************************
*&---------------------------------------------------------------------*
*&      Form  GET_TOP_CODE
*&---------------------------------------------------------------------*
form get_top_code.

  clear lin.
  describe table itab lines lin.
  if lin = 0.
    exit.
  endif.

  loop at itab.
    call function 'CS_WHERE_USED_MAT'
         exporting
              datub                      = bdate-high
              datuv                      = bdate-low
              matnr                      = itab-matnr
              werks                      = werks
         tables
              wultb                      = usedtab
              equicat                    = equicat
              kndcat                     = kndcat
              matcat                     = matcat
              stdcat                     = stdcat
              tplcat                     = tplcat
         exceptions
              call_invalid               = 1
              material_not_found         = 2
              no_where_used_rec_found    = 3
              no_where_used_rec_selected = 4
              no_where_used_rec_valid    = 5
              others                     = 6.

    clear line_cnt.
    describe table usedtab lines line_cnt.
    if line_cnt = 0.          
      move itab-matnr to top_code-matnr.
      top_code-menge = itab-menge.
      collect top_code.
      clear top_code.
    else.
      loop at usedtab where postp ne 'F' and datuv le bdate-high
                      and ( sumfg = ' ' or sumfg = 'x' ).
        select single lkenz into stas-lkenz from stas
               where stlty = 'M'
               and   stlnr = usedtab-stlnr
               and   stlal = '01'
               and   stlkn = usedtab-stlkn
               and   datuv le bdate-low
               and   lkenz = 'X'.
        if sy-subrc ne 0.
          move usedtab-matnr to alttab-matnr.
          alttab-menge = usedtab-menge * itab-menge.
          collect alttab.
        endif.
        clear alttab.
      endloop.
    endif.
    refresh : usedtab,equicat,kndcat,matcat,stdcat,tplcat.

  endloop.

  refresh itab.
  itab[] = alttab[].
  refresh alttab.
  perform get_top_code.

endform.                    " GET_TOP_CODE

 

posted @ 2019-07-14 11:18  SAPmatinal  阅读(2005)  评论(0编辑  收藏  举报